# Maintainer: Evangelos Foutras <evangelos@foutrelis.com>
# Contributor: Jan "heftig" Steffens <jan.steffens@gmail.com>

pkgname=lldb
pkgver=7.0.0
pkgrel=1
pkgdesc="Next generation, high-performance debugger"
arch=('x86_64')
url="https://lldb.llvm.org/"
license=('custom:University of Illinois/NCSA Open Source License')
depends=('llvm-libs' 'clang' 'python2' 'python2-six')
makedepends=('llvm' 'cmake' 'ninja' 'swig')
source=(https://releases.llvm.org/$pkgver/$pkgname-$pkgver.src.tar.xz{,.sig})
sha256sums=('7ff6d8fee49977d25b3b69be7d22937b92592c7609cf283ed0dcf9e5cd80aa32'
            'SKIP')
validpgpkeys+=('B6C8F98282B944E3B0D5C2530FC3042E345AD05D') # Hans Wennborg <hans@chromium.org>
validpgpkeys+=('474E22316ABF4785A88C6E8EA2C794A986419D8A') # Tom Stellard <tstellar@redhat.com>

prepare() {
  cd "$srcdir/$pkgname-$pkgver.src"
  mkdir build
}

build() {
  cd "$srcdir/$pkgname-$pkgver.src/build"

  cmake .. -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DPYTHON_EXECUTABLE=/usr/bin/python2 \
    -DPYTHON_LIBRARY=/usr/lib/libpython2.7.so \
    -DPYTHON_INCLUDE_DIR=/usr/include/python2.7 \
    -DLLVM_LINK_LLVM_DYLIB=ON \
    -DLLDB_USE_SYSTEM_SIX=1
  ninja
}

package() {
  cd "$srcdir/$pkgname-$pkgver.src/build"

  DESTDIR="$pkgdir" ninja install
  install -Dm644 ../LICENSE.TXT "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  # Install possibly outdated man page; better than nothing!
  install -Dm644 ../docs/lldb.1 "$pkgdir/usr/share/man/man1/lldb.1"

  # Remove static libraries
  rm "$pkgdir"/usr/lib/*.a

  # Relocate custom readline.so module which links agaisnt libedit
  mv "$pkgdir"/usr/lib/python2.7/site-packages/{,lldb/}readline.so
  sed -i '2isys.path.insert(1, "/usr/lib/python2.7/site-packages/lldb")' \
    "$pkgdir/usr/lib/python2.7/site-packages/lldb/embedded_interpreter.py"

  # Compile Python scripts
  python2 -m compileall "$pkgdir"
  python2 -O -m compileall "$pkgdir"
}

# vim:set ts=2 sw=2 et:
